package cn.lxh.basic.service.jobhandler;

import cn.lxh.system.domain.WxtemplateReq;
import cn.lxh.system.service.impl.WxAccountServiceImpl;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName XhXsXxlJob
 * @Description TODO
 * @Author luoxiaohu
 * @Date 2023/7/10 16:38
 * @Vsersion 1.0
 **/
@Component
@Slf4j
public class XhXsXxlJob {

    private static Logger logger = LoggerFactory.getLogger(XhXsXxlJob.class);
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private WxAccountServiceImpl wxAccountService;


    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello World.");

        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at23239:" + i);
            System.out.println(i+"siajfajfo");
            TimeUnit.SECONDS.sleep(2);
        }
        // default success
    }

    /**
     * 每天早上六点
     * @throws Exception
     */
    @XxlJob("publicContentHandler")
    public void publicContentHandler() {
        try {

            XxlJobHelper.log("微信公众号模板内容start...");
            wxAccountService.getApiInfo();
            XxlJobHelper.log("微信公众号模板内容end...");
        } catch (Exception e) {
            log.error("模板填充内容定时任务异常"+e);
        }

    }

    /**
     * 每天9点发送 公众号兴 sendWxSms
     * @throws Exception
     */
    @XxlJob("publicSmsHandler")
    public void publicSmsHandler() {
        try {
            XxlJobHelper.log("微信公众号——发送消息tart...");
            WxtemplateReq wxtemplateReq = new WxtemplateReq();
            wxAccountService.sendWxSms(wxtemplateReq);
            XxlJobHelper.log("微信公众号——发送消息end...");
        } catch (Exception e) {
            log.error("公共号发送消息异常"+e);
        }

    }

}
